<?php

namespace App\Enums\Message;

use App\Traits\EnumTrait;

class MessagePayloadTypeEnum
{
    use EnumTrait;

    const ORDER = ['type' => 1, 'text' => '订单'];
    const CONTENT_AUDIT = ['type' => 2, 'text' => '发布内容审核'];
    const ACCOUNT_FREEZE = ['type' => 3, 'text' => '账号冻结'];
    const ACCOUNT_SHUTUP = ['type' => 4, 'text' => '账号禁言'];
    const LEAVE_MESSAGE = ['type' => 5, 'text' => '留言'];
    const COMMENT = ['type' => 6, 'text' => '评论'];
    const SUBSCRIBE = ['type' => 7, 'text' => '关注'];
    const PRAISE = ['type' => 8, 'text' => '点赞'];
    const REPLY = ['type' => 9, 'text' => '回复'];

    public static array $typeToText = [];

    public static function getType($data)
    {
        return $data['type'];
    }

    public static function getText($data)
    {
        return $data['text'];
    }

    public static function getTextByType(int $type)
    {
        if (empty(self::$typeToText)) {
            self::$typeToText = array_column(self::getConstants(), 'text', 'type');
        }
        return self::$typeToText[$type] ?? '';
    }
}
